package com.szhn.aclservice.controller;


import com.szhn.aclservice.entity.AclRole;
import com.szhn.aclservice.service.AclRoleService;
import com.szhn.common.responsejson.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-10-28
 */
@RestController
@RequestMapping("/aclservice/acl-role")
public class AclRoleController {

    @Autowired
    private AclRoleService aclRoleService;

    @ApiOperation("根据id查询角色")
    @GetMapping("getRoleById/{id}")
    public R getRoleById(@PathVariable String id){
        AclRole role = aclRoleService.getById(id);
        return role != null ? R.ok() : R.error();
    }

    @ApiOperation("查询所有角色")
    @GetMapping("getAll")
    public R getAll(){
        List<AclRole> list = aclRoleService.list(null);
        return R.ok().data("list",list);
    }

    @ApiOperation("根据id删除角色")
    @DeleteMapping("deleteById/{id}")
    public R deleteById(@PathVariable String id){
        boolean flag = aclRoleService.removeById(id);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation("根据id批量删除")
    @DeleteMapping("delteByIds")
    public R deleteByIds(@RequestBody List<String> ids){
        boolean flag = aclRoleService.removeByIds(ids);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation("修改角色信息")
    @PutMapping("updete")
    public R update(@RequestBody AclRole aclRole){
        boolean flag = aclRoleService.updateById(aclRole);
        return flag ? R.ok() : R.error();
    }

}

